<%@page import="com.jfinal.kit.PropKit"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="cn.com.dashihui.web.common.OrderCode" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<title>积分抵现</title>
<jsp:include page="../../include/header.jsp"></jsp:include>
<style type="text/css">
table td {
	text-align: center;
	white-space: normal;
	overflow: hidden;
	text-overflow: ellipsis;
}

table th {
	text-align: center;
}
</style>
</head>
<body>
	<div id="wrapper" class="row">

		<div class="col-lg-12">
			<h1 class="page-header">抵现明细</h1>
		</div>
		<!-- 搜索框 -->
		<div class="title-top col-lg-12">
			<label class="search-label">买家电话：</label><input type="text" id="sTel"
				value="" class="form-control search-input width100" maxlength="13">
			<label class="search-label">选择销售：</label><input type="text"
				id="toBossOneId" value="" class="form-control search-input width100"
				maxlength="13">
			<c:if test="${RoleId==2}">
				<label class="search-label">选择分公司：</label>
				<%--  <select id="sStoreId" class="selectpicker pull-left p-l-5" data-width="10%" data-url="${BASE_PATH}/api/Orderstore/${sellerId}" data-isfirst="true"  data-key="storeid:title"></select>  --%>
				<select id=sStoreId class="selectpicker pull-left p-l-5"
					multiple="multiple" data-width="120">
					<c:forEach items="${list }" var="Store">
						<option value="${Store.storeid }">${Store.title }</option>
					</c:forEach>
				</select>
			</c:if>
			<%-- <select id="sStoreId" class="selectpicker pull-left p-l-5" data-width="10%" data-url="${BASE_PATH}/api/storeAll" data-isfirst="true"   data-key="storeid:title"></select>  --%>
			<label class="search-label">消费时间：</label><input type="text"
				id="sBeginDate" value=""
				class="form-control search-input width120 datetimepicker"
				data-format="yyyy-mm-dd" > <label
				class="search-label">至</label><input type="text" id="sEndDate"
				value="" class="form-control search-input width120 datetimepicker"
				data-format="yyyy-mm-dd" >
			<button class="btn btn-success search-btn" onclick="query();">确定</button>
			<button class="btn btn-success search-btn" onclick="reset();">重置</button>
			<c:if test="${session.userpopedom.busOrderDixianlistDoExcel==1}">
				<button onclick="doExcel();" class="btn btn-success pull-right">导出</button>
			</c:if>
			<div class="clearfix"></div>
		</div>

		<div class="col-lg-12">
			<div class="col-lg-12">
				<div class="text-muted single-line-text pull-left">
					共 <font color="#428bca" id="dataCount">0</font> 条记录
				</div>

			</div>
			<!-- table-responsive表格的下编框的滚动条 -->
			<div class="table-responsive panel panel-default ">
				<table id="dataTable"
					class="table  table-hover table-noellipsis table-bordered"
					style="overflow: scroll;">
					<thead>
						<tr>
							<th width="300px">消费分公司</th>
							<th width="100px">会员姓名</th>
							<th width="150px">联系方式</th>
							<th width="300px">开卡分公司</th>
							<th width="100px">销售</th>
							<th width="500px">消费项目</th>
							<th width="200px">消费金额</th>
							<th width="100px">抵现金额</th>
							<th width="180px">消费时间</th>
						</tr>
					</thead>
					<tbody id="dataList"></tbody>
				</table>
			</div>

			<div class="col-lg-12">
				<ul id="dataPagination" class="pagination-sm pull-right"></ul>
			</div>

		</div>


	</div>
	<jsp:include page="../../include/javascripts.jsp"></jsp:include>
	<!-- 异步加载下一页数据后，用模板渲染 -->
	<script type="text/html" id="dataTpl">
	   {{each list as item}}
				 <tr id="item{{item.orderNum}}" data-id="{{item.orderNum}}">
					<td>{{item.title}}</td>
					<td>{{item.name}}</td>
					<td>{{item.phone}}</td>
					<td>{{item.store}}</td>
					<td>{{item.toBossOneId}}</td>
					<td>{{item.mun}}</td>
					<td>{{item.money}}</td>
					<td>{{item.amount}}</td>
					<td>{{item.date}}</td>
				</tr>
	{{/each}}
</script>
	<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	sStoreId = $("#sStoreId").val();
	var store;
	if(sStoreId !=null && sStoreId !="" && sStoreId !=undefined){
		store=sStoreId.join("','");
	}
	
	var params = {
		pageSize:10,
		toBossOneId:$("#toBossOneId").val(),
		beginDate:$("#sBeginDate").val(),
		endDate:$("#sEndDate").val(),
		phone:$("#sTel").val(),
		sStoreId:store
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/bus/order/dixianpage",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}

function doExcel(){
	
     	 var toBossOneId=$("#toBossOneId").val(),beginDate = $("#sBeginDate").val(),endDate = $("#sEndDate").val(), phone = $("#sTel").val(),storeId = $("#sStoreId").val();
     	var store="";
    	
    	if(sStoreId !=null && sStoreId !="" && sStoreId !=undefined){
    		store=sStoreId.join("','");
    	}
     	 window.location.href="${BASE_PATH}/bus/order/doDixianExcel?toBossOneId="+toBossOneId+"&beginDate="+beginDate+"&endDate="+endDate+"&phone="+phone+"&sStoreId="+store;
	};
	$("#sBeginDate").datetimepicker({
	    format: 'yyyy-mm-dd hh:ii:ss',
	    minuteStep:1,
	    minView:'hour',
	    language: 'zh-CN',
	    pickerPosition:'bottom-right',
	    autoclose:true,
	}).on("click",function(){
		var d2=new Date();
		var d=$("#sEndDate").val();
		if(d==""){
			 $("#sBeginDate").datetimepicker("setEndDate",d2);
		}else{
			var d1=new Date(d); 
			d1.setDate(d1.getDate()-1);
			if(d1>d2){
		  	 	 $("#sBeginDate").datetimepicker("setEndDate",d2);
			}else{
				 $("#sBeginDate").datetimepicker("setEndDate",d1);
			}
		}
	});

	$("#sEndDate").datetimepicker({
	    format: 'yyyy-mm-dd hh:ii:ss',
	    minuteStep:1,
	    minView:'hour',
	    language: 'zh-CN',
	    autoclose:true,
		}).on("click",function(){
			var d=$("#sBeginDate").val();
			var d1=new Date(d); 
			d1.setDate(d1.getDate()+1); 
			$("#sEndDate").datetimepicker("setStartDate",d1);
		});
		
	 $(document).on("click","#sEndDate",function(){
	    	$('#sEndDate').datetimepicker('show');
	    });

	$(document).on("click","#sBeginDate",function(){
		$('#sBeginDate').datetimepicker('show');
	});
	function reset(){
		$("#sBeginDate").val("");$("#sEndDate").val("");$("#sTel").val(""); $("#sStoreId").val("");$("#sStoreId").trigger("change");
		$("#toBossOneId").val("");$("#sStoreId").selectpicker("refresh"); $("#sSellerId").selectpicker("refresh");
	}
</script>
</body>
</html>